<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Where is Schtief</title>
    <script src="prototype.js" type="text/javascript"></script>
    <script src="calendar_date_select.js" type="text/javascript"></script>
    <script src="format_finnish.js" type="text/javascript"></script>
	<link href="silver.css" media="screen" rel="stylesheet" type="text/css" />
	
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAd1mTWhhIf0BDdkWVS78vshQ8O2Rrwn_syHWXxA1_wLHAaTolExSVr1TGtIN58GjZWjW31betl2bmZw"
      type="text/javascript"></script>
    <script type="text/javascript">
var map;
var latestPos;
var entries;
var error="";
function load() {
	if (!GBrowserIsCompatible()) {
		document.getElementById("error").innerHTML = "Not compatible!";
		return;
	}

	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	//map.addControl(new GMapTypeControl()); 

	update();
}

function update(){
	map.clearOverlays();
	latestPos=null;
	for (var i = 0; i < entries.length; i++) {
		try{
			var entry = entries[i];
			var info = entry['info'];
			var tweets = entry['tweets'];
			var flickr = entry['flickr'];
			var type = entry['type'];
			var lon =  entry['latitude'];	
			var lat =  entry['longitude'];
			if(null==latestPos){

			}
			else{
				var polyline = new GPolyline([latestPos,new GLatLng(lat, lon)], "#aa0000", 5);
				map.addOverlay(polyline);
			}
			latestPos = new GLatLng(lat, lon);
			map.addOverlay(createMarker(latestPos, info, type, i, tweets,flickr));  
		}catch(e){
			error += e.name+" : "+ e.message;
			document.getElementById("error").innerHTML =error;
		}
		map.setCenter(latestPos, 12);
	}
}

function createMarker(point, info, type, id, tweets,flickr) {
	id=id+1;
	var icon;

	if(type=="location")
		icon = new GIcon(G_DEFAULT_ICON,"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+id+"|ff2222|000000"); 

	if(type=="cluster")
		icon = new GIcon(G_DEFAULT_ICON,"http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=home|FFFF00");

	if(type=="actual")
		icon = new GIcon(G_DEFAULT_ICON,"http://chart.apis.google.com/chart?chst=d_map_xpin_icon&chld=pin_star|home|00FFFF|FF0000");
	
	var marker = new GMarker(point, {icon:icon, zIndexProcess:orderOfCreation});
	var tweetInfo="";
	if(tweets.length>3){
		for (var t = 0; t < tweets.length; t++) {
			tweetInfo=tweetInfo+"<a href='http://twitter.com/"+tweets[t].user+"/status/"+tweets[t].id+"' target='_twitter'>"+tweets[t].time+"</a>";
			if(t+1<tweets.length)
				tweetInfo=tweetInfo+",&nbsp;";
		}
	}
	else{
		for (var t = 0; t < tweets.length; t++) {
			tweetInfo=tweetInfo+"<a href='http://twitter.com/"+tweets[t].user+"/status/"+tweets[t].id+"' target='_twitter'>"+tweets[t].time+"</a>&nbsp;"+breakString(tweets[t].text,60);
			if(t+1<tweets.length)
				tweetInfo=tweetInfo+"<br/>";
		}
	}
	
	if(tweetInfo.length>0)
	  tweetInfo="<div style='font-size:12px;font-family:arial'>"+tweetInfo+"</div>";
	
	var flickrInfo="";
	if (undefined != flickr){
		flickrInfo="<div style='font-size:12px;font-family:arial'><a href='http://www.flickr.com/photos/lischke/"+flickr.id+"' target='_flickr'><img src='"+flickr.thumbnail+"' border='0'/></a></div>";
	}
	
	GEvent.addListener(marker, "mouseover", function() {
		marker.openInfoWindowHtml("<div style='font-size:12px;font-family:arial;font-weight:bold'>" + info + "</div>"+tweetInfo+flickrInfo);
	});    
  	return marker;
}

      function breakString(s,len){
      	var res=s;
      	if(s.length>len){
      		res=s.substr(0,len);
      		res=res+"<br/>"+s.substr(len);
      	}
      	return res;
      }

      function orderOfCreation(marker,b) { 
        return 1; 
      } 
      
function setUserDate(){
	new Ajax.Request('/whereisschtief', {
	  method: 'get',
	  parameters: {action: 'getdata', callback: 'updateLocations', date: document.forms[0].date.value, name: document.forms[0].user.value}
	  });
}
   
function updateLocations(root){
	entries = root.locations || [];
	update();
} 
    
function listLocations(root) {
	entries = root.locations || [];
}
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
  <center>
  <form><b>User:</b><select id="user" name="user" ><option selected>mrschtief</option><option>fritz</option><option>plomlompom</option><option>martinhaase</option><option>alex</option><option>kr1sp1n</option></select>
  <input id="date" name="date" type="text" value="" onChange="setUserDate()" /><img alt="Calendar" onclick="new CalendarDateSelect( $(this).previous(), {year_range:10} );" src="calendar.gif" style="border:0px; cursor:pointer;" /><b>&lt;-- Where was Schtief on (click on Calendar icon!)</b></form>
  <div id="map" style="width:600px;height:400px"></div>
  <div id="error"></div> 
  </center>
  TODOS:<br/>
  <ul><li><strike>Clustering: Verweildauer an den Orten aufsummieren </strike></li>
  <li><strike>Integration von Twitter</strike>/Flickr und evtl. meiner Anrufdaten</li>
  <li>Ungewoehnliche Orte herausfilter und extra anzeigen.<br/>(Treffen mit Terroristen/Urlaub in Pakistan)</li>
  <li><strike>Multiusererweiterung</strike> & Community :-)</li>
  </ul>
  
<script src="/whereisschtief?action=getdata&callback=listLocations&name=mrschtief">
</script>
  <script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-5877296-7");
pageTracker._trackPageview();
} catch(err) {}</script></body>
</html>